package clone;

import java.util.ArrayList;
import java.util.List;

public class Main {
    public static void main(String[] args) throws CloneNotSupportedException {
        List<Student> students = new ArrayList<Student>() {{
            add(new Student("张三"));
            add(new Student("李四"));
        }};
        Teacher teacher1 = new Teacher("王老师", students);
        Teacher teacher2 = teacher1.shallowClone();
        Teacher teacher3 = teacher1.deepClone();
        System.out.println("teacher1: " + teacher1);
        System.out.println("teacher2: " + teacher2); // 浅克隆
        System.out.println("teacher3: " + teacher3); // 深克隆
        teacher1.students.add(new Student("王五"));
        System.out.println("=================teacher1增加了学生王五=================");
        System.out.println("teacher1: " + teacher1);
        System.out.println("teacher2: " + teacher2); // 浅克隆
        System.out.println("teacher3: " + teacher3); // 深克隆
    }
}
